home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / misc / prtfolio / sft.arj / TMIO.ASM < prev    next >
Assembly Source File  |  1993-07-21  |  21KB  |  847 lines

  1. ; serial port routines for ibm-pc, including atari portfolio
  2.  
  3. ; r. henze  17.07.90
  4. ; last edit 21.07.93
  5.  
  6.            NAME     TMIO
  7.  
  8. ;Unterscheidung der Versionen:
  9. ;  a86       tmio.asm tmio_ibm.obj   : ibm, com1
  10. ;  a86 =ptf  tmio.asm tmio_ptf.obj   : portfolio
  11.  
  12. ;82C50 constants:
  13.  
  14. ser_bas1 equ        402h        ;com2
  15. ser_bas0 equ        400h        ;com1
  16.  
  17. rbr        equ        0h        ;receiver reg
  18. thr        equ        0h        ;transmitter
  19. ier        equ        1h        ;interrupt en
  20. iir        equ        2h        ;interrupt id
  21. lcr        equ        3h        ;line ctrl
  22. mcr        equ        4h        ;modem ctrl
  23. lsr        equ        5h        ;line status
  24. msr        equ        6h        ;modem status
  25.  
  26. ;interrupt controller:
  27. int_reg    equ        807fh     ;adr ser vect reg
  28. int_on     equ        01h       ;enable int
  29. int_off    equ        00h       ;disable int
  30. #if com2
  31.   iintnum    equ        0bh       ;int number com2
  32.   iintena    equ       0f7h       ;int enable com2
  33.   iintdsa    equ        08h       ;int disable com2
  34. #else
  35.   iintnum    equ        0ch       ;int number com1
  36.   iintena    equ       0efh       ;int enable com1
  37.   iintdsa    equ        10h       ;int disable com1
  38. #endif
  39.  
  40. ;control bytes:
  41. dtr        equ        01h
  42. rts        equ        02h
  43. thre_mask  equ        20h
  44.  
  45.  
  46. ;miscelaneous definitions
  47. cr         equ        0dh
  48. lf         equ        0ah
  49. ;port_default equ 83h        ; 8 bit, 1 stop bit, 1200 baud
  50. port_default equ 0e3h        ; 8 bit, 1 stop bit, 9600 baud
  51. strp_top     equ 7fh
  52.  
  53.  
  54. ;memory allocation blocks:
  55. buf_len    equ        500h        ;input buffer
  56. stk_len    equ        200h        ;stack
  57.  
  58. ;------------------------------------
  59.  
  60. DGROUP  GROUP _DATA,_BSS
  61.  
  62. _DATA   SEGMENT WORD PUBLIC 'DATA'
  63.  
  64.         public _port_stat
  65.         public _tmdp_cnt
  66.  
  67. tmio_base dw 0
  68. tmio_offc dw 0
  69. tmio_segc dw 0
  70.  
  71. _port_stat dw 0
  72. port_par  dw port_default
  73.  
  74. ;buffer storage
  75. tmdp_cbuf db buf_len dup (00)
  76.  
  77. tmdp_head dw offset tmdp_cbuf
  78. tmdp_tail dw offset tmdp_cbuf
  79. _tmdp_cnt  dw 0
  80. ;tmdp_ful  dw 0
  81. scratch   dw 0
  82.  
  83. com_port  dw 0
  84.  
  85. int_num    dw  000ch       ;int number com1
  86. int_ena    dw  00efh       ;int enable com1
  87. int_dsa    dw  0010h       ;int disable com1
  88.  
  89. ctc_flag dw 00             ;control-c flag
  90.  
  91. _DATA   ENDS
  92.  
  93. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  94. _BSS    ENDS
  95.  
  96. ;------------------------------------
  97.  
  98. _TEXT   SEGMENT BYTE PUBLIC 'CODE'
  99.         ASSUME        CS: _TEXT, DS: _DATA
  100.  
  101.         public        _send_com
  102.         public        _exit_com
  103.         public        _tmio_setup
  104.         public        _receive_com
  105.         public        _cout
  106.         public        _put
  107.         public        _hex
  108.         public        _hex8
  109.  
  110.  
  111. ;Control-C abfangen:
  112.  
  113.         public        _nobreak
  114.         public        _get_ctc
  115.  
  116. ;***** aufruf in c:
  117.  
  118. ;extern void nobreak ();
  119. ;extern int get_ctc ();
  120.  
  121. ;------------------------------------
  122.  
  123. ;tmio_setup
  124. ;sets up serial port
  125. ;parmeters : port parameter-byte
  126. ;returns   : none
  127. ;destroys  : none
  128.  
  129.  
  130. _tmio_setup proc near
  131.         push       bp
  132.         push       ax
  133.  
  134.         mov        bp,sp
  135.         mov        ax,[bp+6]
  136.         mov        port_par,al
  137.  
  138.         mov        com_port,ah
  139.  
  140.         cmp        com_port,0
  141.         je         co1
  142.         mov        int_num,0bh       ;int number com2
  143.         mov        int_ena,0f7h      ;int enable com2
  144.         mov        int_dsa,08h       ;int disable com2
  145.         jmp        co2
  146. co1:
  147.         mov        int_num,0ch       ;int number com1
  148.         mov        int_ena,0efh      ;int enable com1
  149.         mov        int_dsa,10h       ;int disable com1
  150. co2:
  151.         push       dx
  152.         cli
  153.         push       bx
  154.         push       es
  155.         mov        al,int_num
  156.         mov        ah,35h
  157.         int        21h
  158.  
  159.         mov        tmio_segc,es        
  160.         mov        tmio_offc,bx
  161.         pop        es
  162.         pop        bx
  163.  
  164.         push       ds
  165.         mov        al,int_num
  166.         mov        ah,25h
  167.         mov        dx,offset cs:_tmio_intc
  168.         mov        ds,cs
  169.         int        21h
  170.  
  171.         pop        ds
  172.  
  173.         sti
  174.         call       _tmio_init
  175.         call       _tmio_inon
  176.  
  177.         pop        dx
  178.         pop        ax
  179.         pop        bp
  180.         ret
  181. _tmio_setup endp
  182.  
  183. ;-----------------------------------
  184.  
  185. ;receive_com
  186. ;get character from buffer
  187. ;parmeters : address where character will be installed
  188. ;returns   : ax : 1 char fetched, 0 no char fetched
  189. ;destroys  : none
  190.  
  191. _receive_com proc near
  192.  
  193.         push        bp
  194.         push        dx
  195.         push        di
  196.         push        si
  197.  
  198.         mov         bp,sp
  199.         mov         ax,[bp+10]      ;save parameter
  200.         cmp         _tmdp_cnt,0      ;buffer empty?
  201.         jle         gete0
  202.  
  203.         push        ax              ;save char pointer
  204.         mov         di,tmdp_tail
  205.         mov         al,[di]         ;get char from buffer
  206.         mov         scratch,al      ;and save it
  207.         pop         ax              ;get char pointer back
  208.         mov         di,ax
  209.         mov         [di],scratch    ;store char at input pointer
  210.         inc         tmdp_tail       ;and increment pointer
  211.  
  212.         mov         ax,offset tmdp_cbuf
  213.         add         ax,buf_len
  214.         cmp         ax,tmdp_tail
  215.  
  216.  
  217.         jg          get1
  218.         mov         ax,offset tmdp_cbuf
  219.         mov         tmdp_tail,ax    ;turn pointer back to start
  220. get1:   dec         _tmdp_cnt      ;decrement buffer count
  221.         mov         ax,1
  222.         jmp         gete1
  223. gete0:  xor         ax,ax
  224. gete1:  pop         si
  225.         pop         di
  226.         pop         dx
  227.         pop         bp
  228.         ret
  229.  
  230. _receive_com endp
  231.  
  232. ;-----------------------------------
  233.  
  234. ; send_com
  235. ; sends a char to serial port
  236. ; stack   : char to send
  237. ; returns : ax = 1
  238. ; destroys: none
  239.  
  240. _send_com proc near
  241.         push       bp
  242.         push       dx
  243.         push       di
  244.  
  245.         mov        bp,sp
  246.         mov        ax,[bp+8]         ;uebergabe parameter
  247.         push       ax
  248.  
  249.         mov        di,tmio_base
  250.         mov        dx,lsr
  251.         add        dx, di
  252. char_wthr:
  253.         in         al,dx
  254.         test       al,thre_mask
  255.         jz         char_wthr
  256.         pop        ax
  257.         mov        dx,thr
  258.         add        dx,di
  259.         out        dx,al
  260.  
  261.         mov        ax,1
  262.         pop        di
  263.         pop        dx
  264.         pop        bp
  265.         ret
  266. _send_com endp
  267.  
  268. ;-----------------------------------
  269.  
  270. ; tmio_init : init serial port
  271. ; 1200 baud, 8 bits, no parity
  272. ; dtr high
  273. ; parameters : none
  274. ; returns:   : none
  275. ; destroys:  :none
  276.  
  277. _tmio_init proc near
  278.         push        ax
  279.         push        si
  280.         push        dx
  281.         push        di
  282.  
  283.         cmp         com_port,0
  284.         je          com1
  285.  
  286.         xor         ax,ax
  287.         push        ds
  288.         mov         ds,ax
  289.         mov         di,[ser_bas1]
  290.         pop         ds
  291.         jmp         com2
  292. com1:
  293.         xor         ax,ax
  294.         push        ds
  295.         mov         ds,ax
  296.         mov         di,[ser_bas0]
  297.         pop         ds
  298. com2:
  299.         mov         tmio_base,di
  300.         call        _tmio_inof
  301.         mov         al,port_par
  302.         call        _tmio_inpt
  303.  
  304. #if ptf
  305. ;code for portfolio:
  306.         mov         ax,int_num
  307.         call        _tmio_sint
  308. #else
  309. ;code for standard ibm-pc:
  310.          in         al,21h
  311.          and        al,int_ena
  312.          out        21h,al
  313. #endif
  314.  
  315. ;set up modem control reg:
  316.         mov        dx,mcr
  317.         add        dx,di
  318.  
  319. #if ptf
  320. ;code for portfolio:
  321.         mov        al,dtr or rts
  322. ;fuer dcf-77 uhr (pin4=high (+), pin7=low (-) 
  323. ;       mov        al,dtr
  324. #else
  325. ;code for standard ibm-pc:
  326.         mov        al,dtr or rts or 8
  327. ;fuer dcf-77 uhr (pin4=high (+), pin7=low (-) 
  328. ;       mov        al,dtr or 8
  329. #endif
  330.  
  331.         out        dx,al
  332.         call       _tmio_inon
  333.         mov        dx,di
  334.         in         al,dx
  335.         pop        di
  336.         pop        dx
  337.         pop        si
  338.         pop